package com.etung.iot.demo.services.impl;

import com.etung.iot.demo.core.SimplePageInfo;
import com.etung.iot.demo.dao.AlarmInfoMapper;
import com.etung.iot.demo.dao.AlarmWarningMapper;
import com.etung.iot.demo.modles.AlarmInfo;
import com.etung.iot.demo.services.AlarmService;
import com.etung.iot.demo.vo.req.AlarmReq;
import com.etung.iot.demo.vo.resp.AlarmRsp;
import com.etung.iot.demo.vo.resp.VariantRealData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class AlarmServiceImpl implements AlarmService {
    @Autowired
    private AlarmWarningMapper alarmWarningMapper;
    @Override
    public SimplePageInfo listData(AlarmReq alarmReq) {
        log.info(alarmReq.toString());
        PageHelper.startPage(alarmReq.getPage(), alarmReq.getLimit());
        List<AlarmRsp> alarmRspList = alarmWarningMapper.selectAlarmInfo(alarmReq);
        PageInfo<AlarmRsp> pageInfo = new PageInfo<>(alarmRspList);
        return new SimplePageInfo<>(pageInfo);
    }

    @Override
    public void ackAlarm(String ids) {
        if (!StringUtils.isEmpty(ids)){
            String[] idArray = ids.split(",");
            List<String> idList = Arrays.asList(idArray);
            Date date = new Date();
            alarmWarningMapper.batchUpdateAlarm(idList,date);
        }
    }
}
